/*****  Identify supermarkets and highways ****/
***** Import Data ***

clear
import delimited "$path\Raw Data\data_PDV.csv", varnames(1) delim(";")
save "$path\Intermediary Data\data_PDV.dta", replace


unicode convertfile "$path\Raw Data\data_PDV_old.csv" ///
 "$path\Intermediary Data\data_PDV_olduttf8.csv", dstencoding(ISO-8859-1) replace
 
clear
import delimited "$path\Intermediary Data\data_PDV_olduttf8.csv", varnames(1) delim(";")
save "$path\Intermediary Data\data_PDV_old.dta", replace



***** Append data and identify duplicates ****
clear
use  "$path\Intermediary Data\data_PDV.dta"
gen new=1
append using "$path\Intermediary Data\data_PDV_old.dta"



*** Check for duplicate longitude/latitude


drop v1
replace cp_commune_pdv=commune_pdv if cp_commune_pdv==""
drop commune_pdv

gen autoroute_bis=autoroute=="Autoroute"
drop autoroute
rename autoroute_bis autoroute


duplicates tag id_pdv, gen(tag)
tab tag 

sort id_pdv
// Among duplicates, identify those located on a highway

bysort id_pdv: egen max_autoroute=max(autoroute)
drop autoroute
rename max_autoroute autoroute

// Then keep only the last version if duplicate

keep if tag==0 | (tag==1 & new==1)
capture drop tag


gen chaine2=strupper(chaine_distrib_pdv)

replace chaine2=subinstr(chaine2, "é", "E",.)
replace chaine2=subinstr(chaine2, "è", "E",.) 
replace chaine2=subinstr(chaine2, "à", "A",.) 


gen chaine3=chaine2
replace chaine3=substr(chaine3, 2, length(chaine3)) if new==1
capture drop new
tabulate chaine3, sort

gen chaine4=chaine3

tab chaine3, sort

/*** Group stations by broad name ***/

replace chaine3="INTERMARCHE" if chaine3=="INTERMARCHE CONTACT"
replace chaine3="INTERMARCHE" if chaine3=="BRICOMARCHE"
replace chaine3="INTERMARCHE" if chaine3=="NETTO"
replace chaine3="INTERMARCHE" if chaine3=="ECOMARCHE"


replace chaine3="CARREFOUR" if chaine3=="CARREFOUR MARKET"
replace chaine3="CARREFOUR" if chaine3=="CARREFOUR CONTACT"
replace chaine3="CARREFOUR" if chaine3=="CARREFOUR EXPRESS"
replace chaine3="CARREFOUR" if chaine3=="CHAMPION"


replace chaine3="AUCHAN" if chaine3=="AUCHAN SUPER"
replace chaine3="AUCHAN" if chaine3=="SIMPLY MARKET"
replace chaine3="AUCHAN" if chaine3=="SIMPLY"


replace chaine3="GEANT" if chaine3=="CASINO"
replace chaine3="GEANT" if chaine3=="SUPER CASINO"



replace chaine3="TOTAL" if chaine3=="TOTAL ACCESS"
replace chaine3="TOTAL" if chaine3=="TOTAL CONTACT"
replace chaine3="TOTAL" if chaine3=="TOTAL BRIE"


replace chaine3="ESSO" if chaine3=="ESSO EXPRESS"
replace chaine3="ESSO" if chaine3=="ESSO SHELL"

replace chaine3="BP" if chaine3=="BP EXPRESS"


replace chaine3="SYSTEME U" if chaine3=="U"
replace chaine3="SYSTEME U" if chaine3=="SYSTEM U"
replace chaine3="SYSTEME U" if chaine3=="U EXPRESS"
replace chaine3="SYSTEME U" if chaine3=="STATION U"
replace chaine3="SYSTEME U" if chaine3=="SUPER U"


replace chaine3="VITO" if chaine3=="VITO CORSE"

replace chaine3="AVIA" if chaine3=="AVIA EXPRESS"


replace chaine3="G20" if chaine3=="SUPERMARCHEG20"
replace chaine3="G20" if chaine3=="G 20"
replace chaine3="G20" if chaine3=="G20 ST FOLQUIN"
replace chaine3="G20" if chaine3=="SUPERMARCHE G20"


replace chaine3="LEADER PRICE" if chaine3=="LEADER-PRICE"

replace chaine3="LECLERC" if chaine3=="E.LECLERC"

replace chaine3="ENI" if chaine3=="ENI FRANCE"

replace chaine3="SPAR" if chaine3=="SUPERMARCHES SPAR"
replace chaine3="SPAR" if chaine3=="SPAR STATION"


replace chaine3="HUIT A 8" if chaine3=="8  A HUIT"

replace chaine3="INDEPENDANT" if chaine3=="INDEPENDANT SANS ENSEIGNE"
replace chaine3="INDEPENDANT" if chaine3=="AUTRE"
replace chaine3="INDEPENDANT" if chaine3=="AUCUNE"


tab chaine3
tab chaine3, sort


gen classif1=chaine3
replace classif1="SUPERMARCHE" if chaine3=="INTERMARCHE" | chaine3=="CARREFOUR" | chaine3=="SYSTEME U" | chaine3=="LECLERC" | chaine3=="GEANT" | chaine3=="AUCHAN" | chaine3=="COLRUYT" | chaine3=="LEADER PRICE" | chaine3=="CORA" | chaine3=="SUPERMARCHE MATCH" | chaine3=="ATAC" | chaine3=="SPAR" | chaine3=="MAXIMARCHE" | chaine3=="SHOPI" | chaine3=="HUIT A 8" | chaine3=="G20" | chaine3=="ALDI" | chaine3=="MONOPRIX" | chaine3=="BI1" | chaine3=="DIA" | chaine3=="COCCIMARKET" | chaine3=="ED"
replace classif1="COMPAGNIE PETROLIERE" if chaine3=="TOTAL" | chaine3=="ESSO"   | chaine3=="AGIP" | chaine3=="SHELL" | chaine3=="BP"  | chaine3=="ELF" | chaine3=="FINA" | chaine3=="ENI"     
replace classif1="DISTRIBUTEUR ESSENCE" if chaine3=="DYNEFF" | chaine3=="ELAN" | chaine3=="AVIA" | chaine3=="VITO" | chaine3=="OIL FRANCE"

tab chaine3 if classif1=="SUPERMARCHE", sort 
tab classif1, sort

gen classif2=chaine3
replace classif2="SUPERMARCHE TOP 6" if chaine3=="INTERMARCHE" | chaine3=="CARREFOUR" | chaine3=="SYSTEME U" | chaine3=="LECLERC" | chaine3=="GEANT" | chaine3=="AUCHAN" 
replace classif2="SUPERMARCHE AUTRES" if chaine3=="COLRUYT" | chaine3=="LEADER PRICE" | chaine3=="CORA" | chaine3=="SUPERMARCHE MATCH" | chaine3=="ATAC" | chaine3=="SPAR" | chaine3=="MAXIMARCHE" | chaine3=="SHOPI" | chaine3=="HUIT A 8" | chaine3=="G20" | chaine3=="ALDI" | chaine3=="MONOPRIX" | chaine3=="BI1" | chaine3=="DIA" | chaine3=="COCCIMARKET" | chaine3=="ED"
replace classif2="COMPAGNIE PETROLIERE" if chaine3=="TOTAL" | chaine3=="ESSO"   | chaine3=="AGIP" | chaine3=="SHELL" | chaine3=="BP"  | chaine3=="ELF" | chaine3=="FINA" | chaine3=="ENI"     
replace classif2="DISTRIBUTEUR ESSENCE" if chaine3=="DYNEFF" | chaine3=="ELAN" | chaine3=="AVIA" | chaine3=="VITO" | chaine3=="OIL FRANCE"



gen supermarche=0
replace supermarche=1 if classif2=="SUPERMARCHE TOP 6"




// Isolate highways among new stations

replace autoroute=1 if strpos(adresse_pdv, "aire")>0 | strpos(adresse_pdv, "Aire")>0  | strpos(adresse_pdv, "AIRE")>0 
replace autoroute=1 if strpos(adresse_pdv, "autoroute")>0 | strpos(adresse_pdv, "Autoroute")>0  | strpos(adresse_pdv, "AUTOROUTE")>0 

replace autoroute=1 if strpos(nomcomplet_pdv, "aire")>0 | strpos(nomcomplet_pdv, "Aire")>0  | strpos(nomcomplet_pdv, "AIRE")>0 
replace autoroute=1 if strpos(nomcomplet_pdv, "autoroute")>0 | strpos(nomcomplet_pdv, "Autoroute")>0  | strpos(nomcomplet_pdv, "AUTOROUTE")>0 

replace autoroute=1 if strpos(nomcomplet_pdv, "a1")>0 | strpos(nomcomplet_pdv, "a2")>0 | strpos(nomcomplet_pdv, "a3")>0 | strpos(nomcomplet_pdv, "a4")>0 | strpos(nomcomplet_pdv, "a5")>0 ///
| strpos(nomcomplet_pdv, "a6")>0 | strpos(nomcomplet_pdv, "a7")>0 | strpos(nomcomplet_pdv, "a8")>0 | strpos(nomcomplet_pdv, "a9")>0 | strpos(nomcomplet_pdv, "a10")>0 | strpos(nomcomplet_pdv, "a11")>0 ///
| strpos(nomcomplet_pdv, "a12")>0 | strpos(nomcomplet_pdv, "a12")>0 | strpos(nomcomplet_pdv, "a13")>0 | strpos(nomcomplet_pdv, "a14")>0 | strpos(nomcomplet_pdv, "a15")>0 | strpos(nomcomplet_pdv, "a16")>0 ///
| strpos(nomcomplet_pdv, "a17")>0 | strpos(nomcomplet_pdv, "a18")>0 | strpos(nomcomplet_pdv, "a19")>0 | strpos(nomcomplet_pdv, "a20")>0 | strpos(nomcomplet_pdv, "a21")>0 | strpos(nomcomplet_pdv, "a22")>0 ///
| strpos(nomcomplet_pdv, "a23")>0 | strpos(nomcomplet_pdv, "a24")>0 | strpos(nomcomplet_pdv, "a25")>0 | strpos(nomcomplet_pdv, "a26")>0 | strpos(nomcomplet_pdv, "a27")>0 | strpos(nomcomplet_pdv, "a28")>0 ///
| strpos(nomcomplet_pdv, "a29")>0 | strpos(nomcomplet_pdv, "a30")>0 | strpos(nomcomplet_pdv, "a31")>0 | strpos(nomcomplet_pdv, "a32")>0 | strpos(nomcomplet_pdv, "a33")>0 | strpos(nomcomplet_pdv, "a34")>0 ///
| strpos(nomcomplet_pdv, "a35")>0 | strpos(nomcomplet_pdv, "a36")>0 | strpos(nomcomplet_pdv, "a37")>0 | strpos(nomcomplet_pdv, "a38")>0 | strpos(nomcomplet_pdv, "a39")>0 | strpos(nomcomplet_pdv, "a40")>0 ///
| strpos(nomcomplet_pdv, "a41")>0 | strpos(nomcomplet_pdv, "a42")>0 | strpos(nomcomplet_pdv, "a43")>0 | strpos(nomcomplet_pdv, "a44")>0 | strpos(nomcomplet_pdv, "a45")>0  ///
| strpos(nomcomplet_pdv, "a46")>0 | strpos(nomcomplet_pdv, "a47")>0 | strpos(nomcomplet_pdv, "a48")>0 | strpos(nomcomplet_pdv, "a49")>0 | strpos(nomcomplet_pdv, "a50")>0 | strpos(nomcomplet_pdv, "a51")>0 ///
| strpos(nomcomplet_pdv, "a52")>0 | strpos(nomcomplet_pdv, "a53")>0 | strpos(nomcomplet_pdv, "a54")>0 | strpos(nomcomplet_pdv, "a55")>0 | strpos(nomcomplet_pdv, "a56")>0 | strpos(nomcomplet_pdv, "a57")>0 ///
| strpos(nomcomplet_pdv, "a58")>0 | strpos(nomcomplet_pdv, "a59")>0 | strpos(nomcomplet_pdv, "a60")>0 | strpos(nomcomplet_pdv, "a61")>0 | strpos(nomcomplet_pdv, "a62")>0 | strpos(nomcomplet_pdv, "a63")>0 ///
| strpos(nomcomplet_pdv, "a64")>0 | strpos(nomcomplet_pdv, "a65")>0 | strpos(nomcomplet_pdv, "a66")>0 | strpos(nomcomplet_pdv, "a67")>0 | strpos(nomcomplet_pdv, "a68")>0 | strpos(nomcomplet_pdv, "a69")>0 ///
| strpos(nomcomplet_pdv, "a70")>0 | strpos(nomcomplet_pdv, "a71")>0 | strpos(nomcomplet_pdv, "a72")>0 | strpos(nomcomplet_pdv, "a73")>0 | strpos(nomcomplet_pdv, "a74")>0 | strpos(nomcomplet_pdv, "a75")>0 ///
| strpos(nomcomplet_pdv, "a76")>0 | strpos(nomcomplet_pdv, "a77")>0 | strpos(nomcomplet_pdv, "a78")>0 | strpos(nomcomplet_pdv, "a79")>0 | strpos(nomcomplet_pdv, "a80")>0 | strpos(nomcomplet_pdv, "a81")>0 ///
| strpos(nomcomplet_pdv, "a82")>0 | strpos(nomcomplet_pdv, "a83")>0 | strpos(nomcomplet_pdv, "a84")>0 | strpos(nomcomplet_pdv, "a85")>0 | strpos(nomcomplet_pdv, "a86")>0 | strpos(nomcomplet_pdv, "a87")>0 ///
| strpos(nomcomplet_pdv, "a88")>0 | strpos(nomcomplet_pdv, "a89")>0 | strpos(nomcomplet_pdv, "a90")>0 | strpos(nomcomplet_pdv, "a91")>0 | strpos(nomcomplet_pdv, "a92")>0 | strpos(nomcomplet_pdv, "a93")>0 ///
| strpos(nomcomplet_pdv, "a94")>0 | strpos(nomcomplet_pdv, "a95")>0 | strpos(nomcomplet_pdv, "a96")>0 | strpos(nomcomplet_pdv, "a97")>0 | strpos(nomcomplet_pdv, "a98")>0 | strpos(nomcomplet_pdv, "a99")>0 ///
| strpos(nomcomplet_pdv, "a100")>0 | strpos(nomcomplet_pdv, "a101")>0 | strpos(nomcomplet_pdv, "a102")>0 | strpos(nomcomplet_pdv, "a103")>0 | strpos(nomcomplet_pdv, "a104")>0 | strpos(nomcomplet_pdv, "a105")>0 ///
| strpos(nomcomplet_pdv, "a106")>0 | strpos(nomcomplet_pdv, "a107")>0 | strpos(nomcomplet_pdv, "a108")>0 | strpos(nomcomplet_pdv, "a109")>0 | strpos(nomcomplet_pdv, "a110")>0 | strpos(nomcomplet_pdv, "a111")>0 ///
| strpos(nomcomplet_pdv, "a112")>0 | strpos(nomcomplet_pdv, "a113")>0 | strpos(nomcomplet_pdv, "a114")>0 | strpos(nomcomplet_pdv, "a115")>0 | strpos(nomcomplet_pdv, "a116")>0 | strpos(nomcomplet_pdv, "a117")>0 ///
| strpos(nomcomplet_pdv, "a118")>0 | strpos(nomcomplet_pdv, "a119")>0 | strpos(nomcomplet_pdv, "a120")>0 | strpos(nomcomplet_pdv, "a121")>0 | strpos(nomcomplet_pdv, "a122")>0 | strpos(nomcomplet_pdv, "a123")>0 ///
| strpos(nomcomplet_pdv, "a124")>0 | strpos(nomcomplet_pdv, "a125")>0 | strpos(nomcomplet_pdv, "a126")>0 | strpos(nomcomplet_pdv, "a127")>0 | strpos(nomcomplet_pdv, "a128")>0 | strpos(nomcomplet_pdv, "a129")>0 ///
| strpos(nomcomplet_pdv, "a130")>0 | strpos(nomcomplet_pdv, "a131")>0 | strpos(nomcomplet_pdv, "a132")>0 | strpos(nomcomplet_pdv, "a139")>0 | strpos(nomcomplet_pdv, "a140")>0 | strpos(nomcomplet_pdv, "a150")>0 ///
| strpos(nomcomplet_pdv, "a150")>0 | strpos(nomcomplet_pdv, "a151")>0 | strpos(nomcomplet_pdv, "a154")>0 | strpos(nomcomplet_pdv, "a203")>0 | strpos(nomcomplet_pdv, "a211")>0 | strpos(nomcomplet_pdv, "a216")>0 ///
| strpos(nomcomplet_pdv, "a304")>0 | strpos(nomcomplet_pdv, "a311")>0 | strpos(nomcomplet_pdv, "a314")>0 | strpos(nomcomplet_pdv, "a315")>0 | strpos(nomcomplet_pdv, "a320")>0 | strpos(nomcomplet_pdv, "a330")>0 ///
| strpos(nomcomplet_pdv, "a340")>0 | strpos(nomcomplet_pdv, "a344")>0 | strpos(nomcomplet_pdv, "a350")>0 | strpos(nomcomplet_pdv, "a351")>0 | strpos(nomcomplet_pdv, "a352")>0 | strpos(nomcomplet_pdv, "a391")>0 ///
| strpos(nomcomplet_pdv, "a401")>0 | strpos(nomcomplet_pdv, "a404")>0 | strpos(nomcomplet_pdv, "a406")>0 | strpos(nomcomplet_pdv, "a410")>0 | strpos(nomcomplet_pdv, "a411")>0 | strpos(nomcomplet_pdv, "a430")>0 ///
| strpos(nomcomplet_pdv, "a432")>0 | strpos(nomcomplet_pdv, "a466")>0 | strpos(nomcomplet_pdv, "a480")>0 | strpos(nomcomplet_pdv, "a500")>0 | strpos(nomcomplet_pdv, "a501")>0 | strpos(nomcomplet_pdv, "a502")>0 ///
| strpos(nomcomplet_pdv, "a507")>0 | strpos(nomcomplet_pdv, "a517")>0 | strpos(nomcomplet_pdv, "a520")>0 | strpos(nomcomplet_pdv, "a551")>0 | strpos(nomcomplet_pdv, "a552")>0 | strpos(nomcomplet_pdv, "a557")>0 ///
| strpos(nomcomplet_pdv, "a570")>0 | strpos(nomcomplet_pdv, "a620")>0 | strpos(nomcomplet_pdv, "a621")>0 | strpos(nomcomplet_pdv, "a623")>0 | strpos(nomcomplet_pdv, "a624")>0 | strpos(nomcomplet_pdv, "a630")>0 ///
| strpos(nomcomplet_pdv, "a631")>0 | strpos(nomcomplet_pdv, "a641")>0 | strpos(nomcomplet_pdv, "a645")>0 | strpos(nomcomplet_pdv, "a660")>0 | strpos(nomcomplet_pdv, "a680")>0 | strpos(nomcomplet_pdv, "a709")>0 ///
| strpos(nomcomplet_pdv, "a711")>0 | strpos(nomcomplet_pdv, "a712")>0 | strpos(nomcomplet_pdv, "a714")>0 | strpos(nomcomplet_pdv, "a719")>0 | strpos(nomcomplet_pdv, "a750")>0 | strpos(nomcomplet_pdv, "a811")>0 ///
| strpos(nomcomplet_pdv, "a813")>0 | strpos(nomcomplet_pdv, "a821")>0 | strpos(nomcomplet_pdv, "a837")>0 | strpos(nomcomplet_pdv, "a844")>0



replace autoroute=1 if strpos(nomcomplet_pdv, "A1")>0 | strpos(nomcomplet_pdv, "A2")>0 | strpos(nomcomplet_pdv, "A3")>0 | strpos(nomcomplet_pdv, "A4")>0 | strpos(nomcomplet_pdv, "A5")>0 ///
| strpos(nomcomplet_pdv, "A6")>0 | strpos(nomcomplet_pdv, "A7")>0 | strpos(nomcomplet_pdv, "A8")>0 | strpos(nomcomplet_pdv, "A9")>0 | strpos(nomcomplet_pdv, "A10")>0 | strpos(nomcomplet_pdv, "A11")>0 ///
| strpos(nomcomplet_pdv, "A12")>0 | strpos(nomcomplet_pdv, "A12")>0 | strpos(nomcomplet_pdv, "A13")>0 | strpos(nomcomplet_pdv, "A14")>0 | strpos(nomcomplet_pdv, "A15")>0 | strpos(nomcomplet_pdv, "A16")>0 ///
| strpos(nomcomplet_pdv, "A17")>0 | strpos(nomcomplet_pdv, "A18")>0 | strpos(nomcomplet_pdv, "A19")>0 | strpos(nomcomplet_pdv, "A20")>0 | strpos(nomcomplet_pdv, "A21")>0 | strpos(nomcomplet_pdv, "A22")>0 ///
| strpos(nomcomplet_pdv, "A23")>0 | strpos(nomcomplet_pdv, "A24")>0 | strpos(nomcomplet_pdv, "A25")>0 | strpos(nomcomplet_pdv, "A26")>0 | strpos(nomcomplet_pdv, "A27")>0 | strpos(nomcomplet_pdv, "A28")>0 ///
| strpos(nomcomplet_pdv, "A29")>0 | strpos(nomcomplet_pdv, "A30")>0 | strpos(nomcomplet_pdv, "A31")>0 | strpos(nomcomplet_pdv, "A32")>0 | strpos(nomcomplet_pdv, "A33")>0 | strpos(nomcomplet_pdv, "A34")>0 ///
| strpos(nomcomplet_pdv, "A35")>0 | strpos(nomcomplet_pdv, "A36")>0 | strpos(nomcomplet_pdv, "A37")>0 | strpos(nomcomplet_pdv, "A38")>0 | strpos(nomcomplet_pdv, "A39")>0 | strpos(nomcomplet_pdv, "A40")>0 ///
| strpos(nomcomplet_pdv, "A41")>0 | strpos(nomcomplet_pdv, "A42")>0 | strpos(nomcomplet_pdv, "A43")>0 | strpos(nomcomplet_pdv, "A44")>0 | strpos(nomcomplet_pdv, "A45")>0  ///
| strpos(nomcomplet_pdv, "A46")>0 | strpos(nomcomplet_pdv, "A47")>0 | strpos(nomcomplet_pdv, "A48")>0 | strpos(nomcomplet_pdv, "A49")>0 | strpos(nomcomplet_pdv, "A50")>0 | strpos(nomcomplet_pdv, "A51")>0 ///
| strpos(nomcomplet_pdv, "A52")>0 | strpos(nomcomplet_pdv, "A53")>0 | strpos(nomcomplet_pdv, "A54")>0 | strpos(nomcomplet_pdv, "A55")>0 | strpos(nomcomplet_pdv, "A56")>0 | strpos(nomcomplet_pdv, "A57")>0 ///
| strpos(nomcomplet_pdv, "A58")>0 | strpos(nomcomplet_pdv, "A59")>0 | strpos(nomcomplet_pdv, "A60")>0 | strpos(nomcomplet_pdv, "A61")>0 | strpos(nomcomplet_pdv, "A62")>0 | strpos(nomcomplet_pdv, "A63")>0 ///
| strpos(nomcomplet_pdv, "A64")>0 | strpos(nomcomplet_pdv, "A65")>0 | strpos(nomcomplet_pdv, "A66")>0 | strpos(nomcomplet_pdv, "A67")>0 | strpos(nomcomplet_pdv, "A68")>0 | strpos(nomcomplet_pdv, "A69")>0 ///
| strpos(nomcomplet_pdv, "A70")>0 | strpos(nomcomplet_pdv, "A71")>0 | strpos(nomcomplet_pdv, "A72")>0 | strpos(nomcomplet_pdv, "A73")>0 | strpos(nomcomplet_pdv, "A74")>0 | strpos(nomcomplet_pdv, "A75")>0 ///
| strpos(nomcomplet_pdv, "A76")>0 | strpos(nomcomplet_pdv, "A77")>0 | strpos(nomcomplet_pdv, "A78")>0 | strpos(nomcomplet_pdv, "A79")>0 | strpos(nomcomplet_pdv, "A80")>0 | strpos(nomcomplet_pdv, "A81")>0 ///
| strpos(nomcomplet_pdv, "A82")>0 | strpos(nomcomplet_pdv, "A83")>0 | strpos(nomcomplet_pdv, "A84")>0 | strpos(nomcomplet_pdv, "A85")>0 | strpos(nomcomplet_pdv, "A86")>0 | strpos(nomcomplet_pdv, "A87")>0 ///
| strpos(nomcomplet_pdv, "A88")>0 | strpos(nomcomplet_pdv, "A89")>0 | strpos(nomcomplet_pdv, "A90")>0 | strpos(nomcomplet_pdv, "A91")>0 | strpos(nomcomplet_pdv, "A92")>0 | strpos(nomcomplet_pdv, "A93")>0 ///
| strpos(nomcomplet_pdv, "A94")>0 | strpos(nomcomplet_pdv, "A95")>0 | strpos(nomcomplet_pdv, "A96")>0 | strpos(nomcomplet_pdv, "A97")>0 | strpos(nomcomplet_pdv, "A98")>0 | strpos(nomcomplet_pdv, "A99")>0 ///
| strpos(nomcomplet_pdv, "A100")>0 | strpos(nomcomplet_pdv, "A101")>0 | strpos(nomcomplet_pdv, "A102")>0 | strpos(nomcomplet_pdv, "A103")>0 | strpos(nomcomplet_pdv, "A104")>0 | strpos(nomcomplet_pdv, "A105")>0 ///
| strpos(nomcomplet_pdv, "A106")>0 | strpos(nomcomplet_pdv, "A107")>0 | strpos(nomcomplet_pdv, "A108")>0 | strpos(nomcomplet_pdv, "A109")>0 | strpos(nomcomplet_pdv, "A110")>0 | strpos(nomcomplet_pdv, "A111")>0 ///
| strpos(nomcomplet_pdv, "A112")>0 | strpos(nomcomplet_pdv, "A113")>0 | strpos(nomcomplet_pdv, "A114")>0 | strpos(nomcomplet_pdv, "A115")>0 | strpos(nomcomplet_pdv, "A116")>0 | strpos(nomcomplet_pdv, "A117")>0 ///
| strpos(nomcomplet_pdv, "A118")>0 | strpos(nomcomplet_pdv, "A119")>0 | strpos(nomcomplet_pdv, "A120")>0 | strpos(nomcomplet_pdv, "A121")>0 | strpos(nomcomplet_pdv, "A122")>0 | strpos(nomcomplet_pdv, "A123")>0 ///
| strpos(nomcomplet_pdv, "A124")>0 | strpos(nomcomplet_pdv, "A125")>0 | strpos(nomcomplet_pdv, "A126")>0 | strpos(nomcomplet_pdv, "A127")>0 | strpos(nomcomplet_pdv, "A128")>0 | strpos(nomcomplet_pdv, "A129")>0 ///
| strpos(nomcomplet_pdv, "A130")>0 | strpos(nomcomplet_pdv, "A131")>0 | strpos(nomcomplet_pdv, "A132")>0 | strpos(nomcomplet_pdv, "A139")>0 | strpos(nomcomplet_pdv, "A140")>0 | strpos(nomcomplet_pdv, "A150")>0 ///
| strpos(nomcomplet_pdv, "A150")>0 | strpos(nomcomplet_pdv, "A151")>0 | strpos(nomcomplet_pdv, "A154")>0 | strpos(nomcomplet_pdv, "A203")>0 | strpos(nomcomplet_pdv, "A211")>0 | strpos(nomcomplet_pdv, "A216")>0 ///
| strpos(nomcomplet_pdv, "A304")>0 | strpos(nomcomplet_pdv, "A311")>0 | strpos(nomcomplet_pdv, "A314")>0 | strpos(nomcomplet_pdv, "A315")>0 | strpos(nomcomplet_pdv, "A320")>0 | strpos(nomcomplet_pdv, "A330")>0 ///
| strpos(nomcomplet_pdv, "A340")>0 | strpos(nomcomplet_pdv, "A344")>0 | strpos(nomcomplet_pdv, "A350")>0 | strpos(nomcomplet_pdv, "A351")>0 | strpos(nomcomplet_pdv, "A352")>0 | strpos(nomcomplet_pdv, "A391")>0 ///
| strpos(nomcomplet_pdv, "A401")>0 | strpos(nomcomplet_pdv, "A404")>0 | strpos(nomcomplet_pdv, "A406")>0 | strpos(nomcomplet_pdv, "A410")>0 | strpos(nomcomplet_pdv, "A411")>0 | strpos(nomcomplet_pdv, "A430")>0 ///
| strpos(nomcomplet_pdv, "A432")>0 | strpos(nomcomplet_pdv, "A466")>0 | strpos(nomcomplet_pdv, "A480")>0 | strpos(nomcomplet_pdv, "A500")>0 | strpos(nomcomplet_pdv, "A501")>0 | strpos(nomcomplet_pdv, "A502")>0 ///
| strpos(nomcomplet_pdv, "A507")>0 | strpos(nomcomplet_pdv, "A517")>0 | strpos(nomcomplet_pdv, "A520")>0 | strpos(nomcomplet_pdv, "A551")>0 | strpos(nomcomplet_pdv, "A552")>0 | strpos(nomcomplet_pdv, "A557")>0 ///
| strpos(nomcomplet_pdv, "A570")>0 | strpos(nomcomplet_pdv, "A620")>0 | strpos(nomcomplet_pdv, "A621")>0 | strpos(nomcomplet_pdv, "A623")>0 | strpos(nomcomplet_pdv, "A624")>0 | strpos(nomcomplet_pdv, "A630")>0 ///
| strpos(nomcomplet_pdv, "A631")>0 | strpos(nomcomplet_pdv, "A641")>0 | strpos(nomcomplet_pdv, "A645")>0 | strpos(nomcomplet_pdv, "A660")>0 | strpos(nomcomplet_pdv, "A680")>0 | strpos(nomcomplet_pdv, "A709")>0 ///
| strpos(nomcomplet_pdv, "A711")>0 | strpos(nomcomplet_pdv, "A712")>0 | strpos(nomcomplet_pdv, "A714")>0 | strpos(nomcomplet_pdv, "A719")>0 | strpos(nomcomplet_pdv, "A750")>0 | strpos(nomcomplet_pdv, "A811")>0 ///
| strpos(nomcomplet_pdv, "A813")>0 | strpos(nomcomplet_pdv, "A821")>0 | strpos(nomcomplet_pdv, "A837")>0 | strpos(nomcomplet_pdv, "A844")>0


replace autoroute=1 if strpos(adresse_pdv, "a1")>0 | strpos(adresse_pdv, "a2")>0 | strpos(adresse_pdv, "a3")>0 | strpos(adresse_pdv, "a4")>0 | strpos(adresse_pdv, "a5")>0 ///
| strpos(adresse_pdv, "a6")>0 | strpos(adresse_pdv, "a7")>0 | strpos(adresse_pdv, "a8")>0 | strpos(adresse_pdv, "a9")>0 | strpos(adresse_pdv, "a10")>0 | strpos(adresse_pdv, "a11")>0 ///
| strpos(adresse_pdv, "a12")>0 | strpos(adresse_pdv, "a12")>0 | strpos(adresse_pdv, "a13")>0 | strpos(adresse_pdv, "a14")>0 | strpos(adresse_pdv, "a15")>0 | strpos(adresse_pdv, "a16")>0 ///
| strpos(adresse_pdv, "a17")>0 | strpos(adresse_pdv, "a18")>0 | strpos(adresse_pdv, "a19")>0 | strpos(adresse_pdv, "a20")>0 | strpos(adresse_pdv, "a21")>0 | strpos(adresse_pdv, "a22")>0 ///
| strpos(adresse_pdv, "a23")>0 | strpos(adresse_pdv, "a24")>0 | strpos(adresse_pdv, "a25")>0 | strpos(adresse_pdv, "a26")>0 | strpos(adresse_pdv, "a27")>0 | strpos(adresse_pdv, "a28")>0 ///
| strpos(adresse_pdv, "a29")>0 | strpos(adresse_pdv, "a30")>0 | strpos(adresse_pdv, "a31")>0 | strpos(adresse_pdv, "a32")>0 | strpos(adresse_pdv, "a33")>0 | strpos(adresse_pdv, "a34")>0 ///
| strpos(adresse_pdv, "a35")>0 | strpos(adresse_pdv, "a36")>0 | strpos(adresse_pdv, "a37")>0 | strpos(adresse_pdv, "a38")>0 | strpos(adresse_pdv, "a39")>0 | strpos(adresse_pdv, "a40")>0 ///
| strpos(adresse_pdv, "a41")>0 | strpos(adresse_pdv, "a42")>0 | strpos(adresse_pdv, "a43")>0 | strpos(adresse_pdv, "a44")>0 | strpos(adresse_pdv, "a45")>0  ///
| strpos(adresse_pdv, "a46")>0 | strpos(adresse_pdv, "a47")>0 | strpos(adresse_pdv, "a48")>0 | strpos(adresse_pdv, "a49")>0 | strpos(adresse_pdv, "a50")>0 | strpos(adresse_pdv, "a51")>0 ///
| strpos(adresse_pdv, "a52")>0 | strpos(adresse_pdv, "a53")>0 | strpos(adresse_pdv, "a54")>0 | strpos(adresse_pdv, "a55")>0 | strpos(adresse_pdv, "a56")>0 | strpos(adresse_pdv, "a57")>0 ///
| strpos(adresse_pdv, "a58")>0 | strpos(adresse_pdv, "a59")>0 | strpos(adresse_pdv, "a60")>0 | strpos(adresse_pdv, "a61")>0 | strpos(adresse_pdv, "a62")>0 | strpos(adresse_pdv, "a63")>0 ///
| strpos(adresse_pdv, "a64")>0 | strpos(adresse_pdv, "a65")>0 | strpos(adresse_pdv, "a66")>0 | strpos(adresse_pdv, "a67")>0 | strpos(adresse_pdv, "a68")>0 | strpos(adresse_pdv, "a69")>0 ///
| strpos(adresse_pdv, "a70")>0 | strpos(adresse_pdv, "a71")>0 | strpos(adresse_pdv, "a72")>0 | strpos(adresse_pdv, "a73")>0 | strpos(adresse_pdv, "a74")>0 | strpos(adresse_pdv, "a75")>0 ///
| strpos(adresse_pdv, "a76")>0 | strpos(adresse_pdv, "a77")>0 | strpos(adresse_pdv, "a78")>0 | strpos(adresse_pdv, "a79")>0 | strpos(adresse_pdv, "a80")>0 | strpos(adresse_pdv, "a81")>0 ///
| strpos(adresse_pdv, "a82")>0 | strpos(adresse_pdv, "a83")>0 | strpos(adresse_pdv, "a84")>0 | strpos(adresse_pdv, "a85")>0 | strpos(adresse_pdv, "a86")>0 | strpos(adresse_pdv, "a87")>0 ///
| strpos(adresse_pdv, "a88")>0 | strpos(adresse_pdv, "a89")>0 | strpos(adresse_pdv, "a90")>0 | strpos(adresse_pdv, "a91")>0 | strpos(adresse_pdv, "a92")>0 | strpos(adresse_pdv, "a93")>0 ///
| strpos(adresse_pdv, "a94")>0 | strpos(adresse_pdv, "a95")>0 | strpos(adresse_pdv, "a96")>0 | strpos(adresse_pdv, "a97")>0 | strpos(adresse_pdv, "a98")>0 | strpos(adresse_pdv, "a99")>0 ///
| strpos(adresse_pdv, "a100")>0 | strpos(adresse_pdv, "a101")>0 | strpos(adresse_pdv, "a102")>0 | strpos(adresse_pdv, "a103")>0 | strpos(adresse_pdv, "a104")>0 | strpos(adresse_pdv, "a105")>0 ///
| strpos(adresse_pdv, "a106")>0 | strpos(adresse_pdv, "a107")>0 | strpos(adresse_pdv, "a108")>0 | strpos(adresse_pdv, "a109")>0 | strpos(adresse_pdv, "a110")>0 | strpos(adresse_pdv, "a111")>0 ///
| strpos(adresse_pdv, "a112")>0 | strpos(adresse_pdv, "a113")>0 | strpos(adresse_pdv, "a114")>0 | strpos(adresse_pdv, "a115")>0 | strpos(adresse_pdv, "a116")>0 | strpos(adresse_pdv, "a117")>0 ///
| strpos(adresse_pdv, "a118")>0 | strpos(adresse_pdv, "a119")>0 | strpos(adresse_pdv, "a120")>0 | strpos(adresse_pdv, "a121")>0 | strpos(adresse_pdv, "a122")>0 | strpos(adresse_pdv, "a123")>0 ///
| strpos(adresse_pdv, "a124")>0 | strpos(adresse_pdv, "a125")>0 | strpos(adresse_pdv, "a126")>0 | strpos(adresse_pdv, "a127")>0 | strpos(adresse_pdv, "a128")>0 | strpos(adresse_pdv, "a129")>0 ///
| strpos(adresse_pdv, "a130")>0 | strpos(adresse_pdv, "a131")>0 | strpos(adresse_pdv, "a132")>0 | strpos(adresse_pdv, "a139")>0 | strpos(adresse_pdv, "a140")>0 | strpos(adresse_pdv, "a150")>0 ///
| strpos(adresse_pdv, "a150")>0 | strpos(adresse_pdv, "a151")>0 | strpos(adresse_pdv, "a154")>0 | strpos(adresse_pdv, "a203")>0 | strpos(adresse_pdv, "a211")>0 | strpos(adresse_pdv, "a216")>0 ///
| strpos(adresse_pdv, "a304")>0 | strpos(adresse_pdv, "a311")>0 | strpos(adresse_pdv, "a314")>0 | strpos(adresse_pdv, "a315")>0 | strpos(adresse_pdv, "a320")>0 | strpos(adresse_pdv, "a330")>0 ///
| strpos(adresse_pdv, "a340")>0 | strpos(adresse_pdv, "a344")>0 | strpos(adresse_pdv, "a350")>0 | strpos(adresse_pdv, "a351")>0 | strpos(adresse_pdv, "a352")>0 | strpos(adresse_pdv, "a391")>0 ///
| strpos(adresse_pdv, "a401")>0 | strpos(adresse_pdv, "a404")>0 | strpos(adresse_pdv, "a406")>0 | strpos(adresse_pdv, "a410")>0 | strpos(adresse_pdv, "a411")>0 | strpos(adresse_pdv, "a430")>0 ///
| strpos(adresse_pdv, "a432")>0 | strpos(adresse_pdv, "a466")>0 | strpos(adresse_pdv, "a480")>0 | strpos(adresse_pdv, "a500")>0 | strpos(adresse_pdv, "a501")>0 | strpos(adresse_pdv, "a502")>0 ///
| strpos(adresse_pdv, "a507")>0 | strpos(adresse_pdv, "a517")>0 | strpos(adresse_pdv, "a520")>0 | strpos(adresse_pdv, "a551")>0 | strpos(adresse_pdv, "a552")>0 | strpos(adresse_pdv, "a557")>0 ///
| strpos(adresse_pdv, "a570")>0 | strpos(adresse_pdv, "a620")>0 | strpos(adresse_pdv, "a621")>0 | strpos(adresse_pdv, "a623")>0 | strpos(adresse_pdv, "a624")>0 | strpos(adresse_pdv, "a630")>0 ///
| strpos(adresse_pdv, "a631")>0 | strpos(adresse_pdv, "a641")>0 | strpos(adresse_pdv, "a645")>0 | strpos(adresse_pdv, "a660")>0 | strpos(adresse_pdv, "a680")>0 | strpos(adresse_pdv, "a709")>0 ///
| strpos(adresse_pdv, "a711")>0 | strpos(adresse_pdv, "a712")>0 | strpos(adresse_pdv, "a714")>0 | strpos(adresse_pdv, "a719")>0 | strpos(adresse_pdv, "a750")>0 | strpos(adresse_pdv, "a811")>0 ///
| strpos(adresse_pdv, "a813")>0 | strpos(adresse_pdv, "a821")>0 | strpos(adresse_pdv, "a837")>0 | strpos(adresse_pdv, "a844")>0



replace autoroute=1 if strpos(adresse_pdv, "A1")>0 | strpos(adresse_pdv, "A2")>0 | strpos(adresse_pdv, "A3")>0 | strpos(adresse_pdv, "A4")>0 | strpos(adresse_pdv, "A5")>0 ///
| strpos(adresse_pdv, "A6")>0 | strpos(adresse_pdv, "A7")>0 | strpos(adresse_pdv, "A8")>0 | strpos(adresse_pdv, "A9")>0 | strpos(adresse_pdv, "A10")>0 | strpos(adresse_pdv, "A11")>0 ///
| strpos(adresse_pdv, "A12")>0 | strpos(adresse_pdv, "A12")>0 | strpos(adresse_pdv, "A13")>0 | strpos(adresse_pdv, "A14")>0 | strpos(adresse_pdv, "A15")>0 | strpos(adresse_pdv, "A16")>0 ///
| strpos(adresse_pdv, "A17")>0 | strpos(adresse_pdv, "A18")>0 | strpos(adresse_pdv, "A19")>0 | strpos(adresse_pdv, "A20")>0 | strpos(adresse_pdv, "A21")>0 | strpos(adresse_pdv, "A22")>0 ///
| strpos(adresse_pdv, "A23")>0 | strpos(adresse_pdv, "A24")>0 | strpos(adresse_pdv, "A25")>0 | strpos(adresse_pdv, "A26")>0 | strpos(adresse_pdv, "A27")>0 | strpos(adresse_pdv, "A28")>0 ///
| strpos(adresse_pdv, "A29")>0 | strpos(adresse_pdv, "A30")>0 | strpos(adresse_pdv, "A31")>0 | strpos(adresse_pdv, "A32")>0 | strpos(adresse_pdv, "A33")>0 | strpos(adresse_pdv, "A34")>0 ///
| strpos(adresse_pdv, "A35")>0 | strpos(adresse_pdv, "A36")>0 | strpos(adresse_pdv, "A37")>0 | strpos(adresse_pdv, "A38")>0 | strpos(adresse_pdv, "A39")>0 | strpos(adresse_pdv, "A40")>0 ///
| strpos(adresse_pdv, "A41")>0 | strpos(adresse_pdv, "A42")>0 | strpos(adresse_pdv, "A43")>0 | strpos(adresse_pdv, "A44")>0 | strpos(adresse_pdv, "A45")>0  ///
| strpos(adresse_pdv, "A46")>0 | strpos(adresse_pdv, "A47")>0 | strpos(adresse_pdv, "A48")>0 | strpos(adresse_pdv, "A49")>0 | strpos(adresse_pdv, "A50")>0 | strpos(adresse_pdv, "A51")>0 ///
| strpos(adresse_pdv, "A52")>0 | strpos(adresse_pdv, "A53")>0 | strpos(adresse_pdv, "A54")>0 | strpos(adresse_pdv, "A55")>0 | strpos(adresse_pdv, "A56")>0 | strpos(adresse_pdv, "A57")>0 ///
| strpos(adresse_pdv, "A58")>0 | strpos(adresse_pdv, "A59")>0 | strpos(adresse_pdv, "A60")>0 | strpos(adresse_pdv, "A61")>0 | strpos(adresse_pdv, "A62")>0 | strpos(adresse_pdv, "A63")>0 ///
| strpos(adresse_pdv, "A64")>0 | strpos(adresse_pdv, "A65")>0 | strpos(adresse_pdv, "A66")>0 | strpos(adresse_pdv, "A67")>0 | strpos(adresse_pdv, "A68")>0 | strpos(adresse_pdv, "A69")>0 ///
| strpos(adresse_pdv, "A70")>0 | strpos(adresse_pdv, "A71")>0 | strpos(adresse_pdv, "A72")>0 | strpos(adresse_pdv, "A73")>0 | strpos(adresse_pdv, "A74")>0 | strpos(adresse_pdv, "A75")>0 ///
| strpos(adresse_pdv, "A76")>0 | strpos(adresse_pdv, "A77")>0 | strpos(adresse_pdv, "A78")>0 | strpos(adresse_pdv, "A79")>0 | strpos(adresse_pdv, "A80")>0 | strpos(adresse_pdv, "A81")>0 ///
| strpos(adresse_pdv, "A82")>0 | strpos(adresse_pdv, "A83")>0 | strpos(adresse_pdv, "A84")>0 | strpos(adresse_pdv, "A85")>0 | strpos(adresse_pdv, "A86")>0 | strpos(adresse_pdv, "A87")>0 ///
| strpos(adresse_pdv, "A88")>0 | strpos(adresse_pdv, "A89")>0 | strpos(adresse_pdv, "A90")>0 | strpos(adresse_pdv, "A91")>0 | strpos(adresse_pdv, "A92")>0 | strpos(adresse_pdv, "A93")>0 ///
| strpos(adresse_pdv, "A94")>0 | strpos(adresse_pdv, "A95")>0 | strpos(adresse_pdv, "A96")>0 | strpos(adresse_pdv, "A97")>0 | strpos(adresse_pdv, "A98")>0 | strpos(adresse_pdv, "A99")>0 ///
| strpos(adresse_pdv, "A100")>0 | strpos(adresse_pdv, "A101")>0 | strpos(adresse_pdv, "A102")>0 | strpos(adresse_pdv, "A103")>0 | strpos(adresse_pdv, "A104")>0 | strpos(adresse_pdv, "A105")>0 ///
| strpos(adresse_pdv, "A106")>0 | strpos(adresse_pdv, "A107")>0 | strpos(adresse_pdv, "A108")>0 | strpos(adresse_pdv, "A109")>0 | strpos(adresse_pdv, "A110")>0 | strpos(adresse_pdv, "A111")>0 ///
| strpos(adresse_pdv, "A112")>0 | strpos(adresse_pdv, "A113")>0 | strpos(adresse_pdv, "A114")>0 | strpos(adresse_pdv, "A115")>0 | strpos(adresse_pdv, "A116")>0 | strpos(adresse_pdv, "A117")>0 ///
| strpos(adresse_pdv, "A118")>0 | strpos(adresse_pdv, "A119")>0 | strpos(adresse_pdv, "A120")>0 | strpos(adresse_pdv, "A121")>0 | strpos(adresse_pdv, "A122")>0 | strpos(adresse_pdv, "A123")>0 ///
| strpos(adresse_pdv, "A124")>0 | strpos(adresse_pdv, "A125")>0 | strpos(adresse_pdv, "A126")>0 | strpos(adresse_pdv, "A127")>0 | strpos(adresse_pdv, "A128")>0 | strpos(adresse_pdv, "A129")>0 ///
| strpos(adresse_pdv, "A130")>0 | strpos(adresse_pdv, "A131")>0 | strpos(adresse_pdv, "A132")>0 | strpos(adresse_pdv, "A139")>0 | strpos(adresse_pdv, "A140")>0 | strpos(adresse_pdv, "A150")>0 ///
| strpos(adresse_pdv, "A150")>0 | strpos(adresse_pdv, "A151")>0 | strpos(adresse_pdv, "A154")>0 | strpos(adresse_pdv, "A203")>0 | strpos(adresse_pdv, "A211")>0 | strpos(adresse_pdv, "A216")>0 ///
| strpos(adresse_pdv, "A304")>0 | strpos(adresse_pdv, "A311")>0 | strpos(adresse_pdv, "A314")>0 | strpos(adresse_pdv, "A315")>0 | strpos(adresse_pdv, "A320")>0 | strpos(adresse_pdv, "A330")>0 ///
| strpos(adresse_pdv, "A340")>0 | strpos(adresse_pdv, "A344")>0 | strpos(adresse_pdv, "A350")>0 | strpos(adresse_pdv, "A351")>0 | strpos(adresse_pdv, "A352")>0 | strpos(adresse_pdv, "A391")>0 ///
| strpos(adresse_pdv, "A401")>0 | strpos(adresse_pdv, "A404")>0 | strpos(adresse_pdv, "A406")>0 | strpos(adresse_pdv, "A410")>0 | strpos(adresse_pdv, "A411")>0 | strpos(adresse_pdv, "A430")>0 ///
| strpos(adresse_pdv, "A432")>0 | strpos(adresse_pdv, "A466")>0 | strpos(adresse_pdv, "A480")>0 | strpos(adresse_pdv, "A500")>0 | strpos(adresse_pdv, "A501")>0 | strpos(adresse_pdv, "A502")>0 ///
| strpos(adresse_pdv, "A507")>0 | strpos(adresse_pdv, "A517")>0 | strpos(adresse_pdv, "A520")>0 | strpos(adresse_pdv, "A551")>0 | strpos(adresse_pdv, "A552")>0 | strpos(adresse_pdv, "A557")>0 ///
| strpos(adresse_pdv, "A570")>0 | strpos(adresse_pdv, "A620")>0 | strpos(adresse_pdv, "A621")>0 | strpos(adresse_pdv, "A623")>0 | strpos(adresse_pdv, "A624")>0 | strpos(adresse_pdv, "A630")>0 ///
| strpos(adresse_pdv, "A631")>0 | strpos(adresse_pdv, "A641")>0 | strpos(adresse_pdv, "A645")>0 | strpos(adresse_pdv, "A660")>0 | strpos(adresse_pdv, "A680")>0 | strpos(adresse_pdv, "A709")>0 ///
| strpos(adresse_pdv, "A711")>0 | strpos(adresse_pdv, "A712")>0 | strpos(adresse_pdv, "A714")>0 | strpos(adresse_pdv, "A719")>0 | strpos(adresse_pdv, "A750")>0 | strpos(adresse_pdv, "A811")>0 ///
| strpos(adresse_pdv, "A813")>0 | strpos(adresse_pdv, "A821")>0 | strpos(adresse_pdv, "A837")>0 | strpos(adresse_pdv, "A844")>0


duplicates tag id_pdv, gen(tag)
sort id_pdv

gen classif_num=0
replace classif_num=1 if classif2=="SUPERMARCHE TOP 6"
replace classif_num=2 if classif2=="SUPERMARCHE AUTRES"
replace classif_num=3 if classif2=="COMPAGNIE PETROLIERE"
replace classif_num=4 if classif2=="DISTRIBUTEUR ESSENCE"

keep id_pdv autoroute classif_num
save "$path\Intermediary Data\data_PDV_autoroutes_supermarches_v3.dta", replace

/****** Identify longitude and latitude based on price data******/

foreach i of numlist 2007/2018 {
clear 
import delimited "$path\Raw Data\Base_id_pdv_`i'.csv", delim(";") varnames(1)

drop v1
tostring cp, replace
gen year=`i'
save "$path\Intermediary Data\Base_id_pdv_`i'.dta", replace
}


clear
use "$path\Intermediary Data\Base_id_pdv_2007.dta"
append using "$path\Intermediary Data\Base_id_pdv_2008.dta"
append using "$path\Intermediary Data\Base_id_pdv_2009.dta"
append using "$path\Intermediary Data\Base_id_pdv_2010.dta"
append using "$path\Intermediary Data\Base_id_pdv_2011.dta"
append using "$path\Intermediary Data\Base_id_pdv_2012.dta"
append using "$path\Intermediary Data\Base_id_pdv_2013.dta"
append using "$path\Intermediary Data\Base_id_pdv_2014.dta"
append using "$path\Intermediary Data\Base_id_pdv_2015.dta"
append using "$path\Intermediary Data\Base_id_pdv_2016.dta"
append using "$path\Intermediary Data\Base_id_pdv_2017.dta"
append using "$path\Intermediary Data\Base_id_pdv_2018.dta"

duplicates tag longitude latitude, gen(tag)
bysort longitude latitude: egen number_pdv=nvals(id_pdv)
bysort longitude latitude: gen first_obs=1 if _n==1

sort id_pdv year
drop pop adresse ouverture fermeture sauf services
duplicates drop id_pdv, force
drop year

save "$path\Intermediary Data\Base_id_pdv_frompricedata.dta", replace





****** Create data_PDV_autoroutes_supermarches_v3_withlonglat.dta

clear 
use "$path\Intermediary Data\data_PDV_autoroutes_supermarches_v3.dta"
merge 1:1 id_pdv using "$path\Intermediary Data\Base_id_pdv_frompricedata.dta"
keep if _merge!=2
drop _merge 


replace longitude=longitude/100000
replace latitude=latitude/100000

sort id
tostring id_pdv, gen(id_pdv_str)
egen id=group(id_pdv_str)


keep id_pdv id_pdv_str autoroute classif_num longitude latitude cp

save "$path\Intermediary Data\data_PDV_autoroutes_supermarches_v3_withlonglat.dta", replace





**** Identify, for each station, the closest municipality ***
clear
import delimited "$path\Raw Data\laposte_hexasmal.csv", delim(";")
gen data_cp=1
append using "$path\Intermediary Data\data_PDV_autoroutes_supermarches_v3_withlonglat.dta"

sca iter=0

gen codeinsee_nn=.
gen dist_nncodeinsee=10000000

levelsof code_commune_insee_num, local(levels)
foreach l of local levels {
egen long_`l'=max(longitude*(code_commune_insee_num==`l'))
egen lat_`l'=max(latitude*(code_commune_insee_num==`l'))
geodist latitude longitude lat_`l' long_`l', gen(dist_`l') sphere
replace dist_nncodeinsee=dist_`l' if dist_`l'<dist_nncodeinsee
replace codeinsee_nn=`l' if data_cp==. &   abs(dist_nncodeinsee-dist_`l')<0.00001 
drop long_`l' 
drop lat_`l'
drop dist_`l'
sca iter=iter+1
di(iter)
}
drop if data_cp==1
rename codeinsee_nn codeinsee

drop code_commune_insee nom_commune code_postal libelle_acheminement ligne_5 code_commune_insee_num data_cp

save "$path\Intermediary Data\data_PDV_autoroutes_supermarches_v3_withlonglat_mergecodeinsee.dta", replace


*** Data on population ***
clear
import delimited "$path\Raw Data\BTX_TD_POP1A_2016.csv", delim(";")
replace codgeo=subinstr(codgeo, "2A", "99", .)
replace codgeo=subinstr(codgeo, "2B", "99", .)
destring codgeo, replace force
rename codgeo codeinsee
egen pop=rsum(sexe*)
keep codeinsee pop
save "$path\Intermediary Data\BTX_TD_POP1A_2016.dta", replace

** Data on urban units **

clear
import delimited "$path\Raw Data\UU2010_au_01-01-2020.csv", delim(";")
drop v*
replace codgeo=subinstr(codgeo, "2A", "99", .)
replace codgeo=subinstr(codgeo, "2B", "99", .)
destring codgeo, replace force
rename codgeo codeinsee
save "$path\Intermediary Data\UU2010_au_01-01-2020.dta", replace
